﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

namespace WebRSSBuilder.ASP
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           SourceDataContext sd = new SourceDataContext(ConfigurationManager.ConnectionStrings[0].ConnectionString);
            if ( sd.Files.Count<File>() > 0)
                for (int i = 0; i < GridView1.Rows.Count; i++)
                {

                    var tf = (from fi in sd.Files
                              where fi.FileID == int.Parse((GridView1.Rows[i].Cells[1]).Text)
                              select fi).First();
                    if (!User.IsInRole(tf.aspnet_Role.RoleName))
                        GridView1.Rows[i].Visible = false;
                }
        }
        

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

            SourceDataContext sd = new SourceDataContext(ConfigurationManager.ConnectionStrings[0].ConnectionString); 
            var tf = (from fi in sd.Files
                     where fi.FileID == int.Parse(GridView1.SelectedValue.ToString())
                      select fi).First() ;
            File f = (File)tf; 
            Session["FileName"] =f.FileName.Trim();
            Session["FileURL"] = f.FileURL.Trim();
            Session["Role"] = f.aspnet_Role.RoleName.Trim();
            Response.Redirect("ViewRss.aspx"); 
        }
    }
}
